import React, { useContext } from 'react';
import { ConfigProvider, Radio as AntdRadio } from 'antd';
import type { RadioProps as AntdRadioProps } from 'antd';

import { useRadioStyles } from './style';
import { radioThemeConfig } from '../../themes/radio';

// 导出样式扩展 Hook，方便用户使用特殊效果
export { useRadioStyles } from './style';

export interface RadioProps extends AntdRadioProps {
  // 继承所有 antd Radio 属性，无需额外属性
}

const RadioComponent: React.FC<RadioProps> = ({ 
  className,
  ...restProps 
}) => {
  const { styles, cx } = useRadioStyles();
  const context = useContext(ConfigProvider.ConfigContext);
  
  // 合并样式：基础样式 + 用户样式
  const radioClassName = cx(
    styles.enhancedRadio,      // 基础样式增强
    className                   // 用户自定义样式
  );

  return (
    <ConfigProvider
      theme={{
        components: {
          Radio: {
            ...radioThemeConfig,
            ...context?.theme?.components?.Radio,
          },
        },
      }}
    >
      <AntdRadio 
        className={radioClassName} 
        {...restProps} 
      />
    </ConfigProvider>
  );
};

const Radio = Object.assign(RadioComponent, {
  Group: AntdRadio.Group,
  Button: AntdRadio.Button,
});

export { Radio };
export default Radio;
